<template>
  <div class="dashboard-container">
    <template>
      <el-select v-model="clientName" clearable placeholder="请选择FTP客户端">
        <el-option
          v-for="item in clientNames"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-input v-model="ftpPath" placeholder="请输入FTP文件路径" />
      <el-input v-model="localPath" placeholder="请输入待解析FTP文件路径" />
      <el-button type="primary" size="small" @click="downloadFtpFile">下载</el-button>
      <el-button type="primary" size="small" @click="parseFtpFile">解析</el-button>

      <el-input v-model="orderDate" placeholder="请输入需要比对的日期" />
      <el-button type="primary" size="small" @click="compareKafka2Xml">比对</el-button>
      <el-button v-show="compareComplete" @click="closeCompareTable">关闭</el-button>
      <el-table v-show="compareComplete" :data="compareForm" style="width: 100%" @expand-change="convertTopicForm">
        <el-table-column type="expand"  style="width: 100%">
          <template>
            <el-table :data="compareTopicForm" style="width: 100%">
              <el-table-column laebl="议案对比" prop="isEquall" />
              <el-table-column label="A股代码">
                <el-table-column label="采编数据" prop="acode0" />
                <el-table-column label="交易所数据" prop="acode1" />
              </el-table-column>
              <el-table-column label="B股代码">
                <el-table-column label="采编数据" prop="bcode0" />
                <el-table-column label="交易所数据" prop="bcode1" />
              </el-table-column>
              <el-table-column label="优先股股代码">
                <el-table-column label="采编数据" prop="priorityCode0" />
                <el-table-column label="交易所数据" prop="priorityCode1" />
              </el-table-column>
              <el-table-column label="恢复表决权优先股股代码">
                <el-table-column label="采编数据" prop="recoveryPriorityCode0" />
                <el-table-column label="交易所数据" prop="recoveryPriorityCode1" />
              </el-table-column>
              <el-table-column label="是否为主议案">
                <el-table-column label="采编数据" prop="isMainTopics0" />
                <el-table-column label="交易所数据" prop="isMainTopics1" />
              </el-table-column>
              <el-table-column label="累积投票应选数">
                <el-table-column label="采编数据" prop="mustSelectNums0" />
                <el-table-column label="交易所数据" prop="mustSelectNums1" />
              </el-table-column>
              <el-table-column label="议案号">
                <el-table-column label="采编数据" prop="topicNo0" />
                <el-table-column label="交易所数据" prop="topicNo1" />
              </el-table-column>
              <el-table-column label="议案名称">
                <el-table-column label="采编数据" prop="topicName0" />
                <el-table-column label="交易所数据" prop="topicName1" />
              </el-table-column>
              <el-table-column label="议案类型">
                <el-table-column label="采编数据" prop="topicType0" />
                <el-table-column label="交易所数据" prop="topicType1" />
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="会议对比" prop="isEquall" />
        <el-table-column label="证券代码">
          <el-table-column label="采编数据" prop="secCode0" />
          <el-table-column label="交易所数据" prop="secCode1" />
        </el-table-column>
        <el-table-column label="证券简称">
          <el-table-column label="采编数据" prop="secAbbr0" />
          <el-table-column label="交易所数据" prop="secAbbr1" />
        </el-table-column>
        <el-table-column label="会议ID">
          <el-table-column label="采编数据" prop="internalMeetingId0" />
          <el-table-column label="交易所数据" prop="internalMeetingId1" />
        </el-table-column>
        <el-table-column label="会议名称">
          <el-table-column label="采编数据" prop="meetingName0" />
          <el-table-column label="交易所数据" prop="meetingName1" />
        </el-table-column>
        <el-table-column label="会议开始日期">
          <el-table-column label="采编数据" prop="meetingBeginDate0" />
          <el-table-column label="交易所数据" prop="meetingBeginDate1" />
        </el-table-column>
        <el-table-column label="会议结束日期">
          <el-table-column label="采编数据" prop="meetingEndDate0" />
          <el-table-column label="交易所数据" prop="meetingEndDate1" />
        </el-table-column>
        <el-table-column label="会议类型">
          <el-table-column label="采编数据" prop="meetingType0" />
          <el-table-column label="交易所数据" prop="meetingType1" />
        </el-table-column>
        <el-table-column label="A股代码">
          <el-table-column label="采编数据" prop="aCode0" />
          <el-table-column label="交易所数据" prop="aCode1" />
        </el-table-column>
        <el-table-column label="A股简称">
          <el-table-column label="采编数据" prop="aAbbr0" />
          <el-table-column label="交易所数据" prop="aAbbr1" />
        </el-table-column>
        <el-table-column label="A股登记日期">
          <el-table-column label="采编数据" prop="aRegDate0" />
          <el-table-column label="交易所数据" prop="aRegDate1" />
        </el-table-column>
        <el-table-column label="A股最后交易日期">
          <el-table-column label="采编数据" prop="aLastDate0" />
          <el-table-column label="交易所数据" prop="aLastDate1" />
        </el-table-column>
        <el-table-column label="B股代码">
          <el-table-column label="采编数据" prop="bCode0" />
          <el-table-column label="交易所数据" prop="bCode1" />
        </el-table-column>
        <el-table-column label="B股简称">
          <el-table-column label="采编数据" prop="bAbbr0" />
          <el-table-column label="交易所数据" prop="bAbbr1" />
        </el-table-column>
        <el-table-column label="B股登记日期">
          <el-table-column label="采编数据" prop="bRegDate0" />
          <el-table-column label="交易所数据" prop="bRegDate1" />
        </el-table-column>
        <el-table-column label="B股最后交易日期">
          <el-table-column label="采编数据" prop="bLastDate0" />
          <el-table-column label="交易所数据" prop="bLastDate1" />
        </el-table-column>
        <el-table-column label="优先股代码">
          <el-table-column label="采编数据" prop="priorityCode0" />
          <el-table-column label="交易所数据" prop="priorityCode01" />
        </el-table-column>
        <el-table-column label="优先股简称">
          <el-table-column label="采编数据" prop="priorityAbbr0" />
          <el-table-column label="交易所数据" prop="priorityAbbr1" />
        </el-table-column>
        <el-table-column label="优先股登记日期">
          <el-table-column label="采编数据" prop="priorityRegDate0" />
          <el-table-column label="交易所数据" prop="priorityRegDate1" />
        </el-table-column>
        <el-table-column label="优先股最后交易日期">
          <el-table-column label="采编数据" prop="priorityLastDate0" />
          <el-table-column label="交易所数据" prop="priorityLastDate1" />
        </el-table-column>
        <el-table-column label="恢复表决权优先股代码">
          <el-table-column label="采编数据" prop="recoveryPriorityCode0" />
          <el-table-column label="交易所数据" prop="recoveryPriorityCode01" />
        </el-table-column>
        <el-table-column label="恢复表决权优先股简称">
          <el-table-column label="采编数据" prop="recoveryPriorityAbbr0" />
          <el-table-column label="交易所数据" prop="recoveryPriorityAbbr1" />
        </el-table-column>
        <el-table-column label="恢复表决权优先股登记日期">
          <el-table-column label="采编数据" prop="recoveryPriorityRegDate0" />
          <el-table-column label="交易所数据" prop="recoveryPriorityRegDate1" />
        </el-table-column>
        <el-table-column label="恢复表决权优先股最后交易日期">
          <el-table-column label="采编数据" prop="recoveryPriorityLastDate0" />
          <el-table-column label="交易所数据" prop="recoveryPriorityLastDate1" />
        </el-table-column>
      </el-table>
      <el-button v-show="compareComplete" @click="saveCompareResult">保存对比结果</el-button>
      <el-button v-show="compareComplete" @click="forceAccess">强制通过</el-button>
    </template>
  </div>
</template>

<script>
import { getToday } from '@/utils/DateUtil'
export default {
  name: 'CurdFtp',
  data() {
    return {
      clientNames: [],
      clientName: '',
      ftpPath: '',
      localPath: '',
      orderDate: '',
      compareForm: [],
      compareComplete: false,
      compareTopicForm: [],
      tmpTopicList: []
    }
  },
  created() {
    this.getClientNamesByUser()
  },
  methods: {
    downloadFtpFile() {
      const that = this
      const clientName = that.clientName
      const remotePath = that.ftpPath
      const data = {
        clientName,
        remotePath
      }
      that.$store.dispatch('editing/downloadFtpFile', data).then(res => {
        if (res.data) {
          console.log(res.data)
        }
      })
    },
    parseFtpFile() {
      const that = this
      const localPath = that.localPath
      const data = {
        localPath
      }
      that.$store.dispatch('editing/parseFtpFile', data).then(res => {
        if (res.data) {
          console.log(res.data)
        }
      })
    },
    convertTopicForm(row) {
      console.log('%%%%%')
      const that = this
      that.compareTopicForm = []
      for (let i = 0; i < row['topicList'].length; i++) {
        that.compareTopicForm.push({
          acode0: row['topicList'][i]['acodes'][0],
          bcode0: row['topicList'][i]['bcodes'][0],
          isEquall: row['topicList'][i]['isEqual'],
          isMainTopics0: row['topicList'][i]['isMainTopics'][0],
          mustSelectNums0: row['topicList'][i]['mustSelectNums'][0],
          priorityCode0: row['topicList'][i]['priorityCodes'][0],
          recoveryPriorityCode0: row['topicList'][i]['recoveryPriorityCodes'][0],
          secCode0: row['topicList'][i]['secCodes'][0],
          topicName0: row['topicList'][i]['topicNames'][0],
          topicNo0: row['topicList'][i]['topicNos'][0],
          topicType0: row['topicList'][i]['topicTypes'][0],
          acode1: row['topicList'][i]['acodes'][1],
          bcode1: row['topicList'][i]['bcodes'][1],
          isMainTopics1: row['topicList'][i]['isMainTopics'][1],
          mustSelectNums1: row['topicList'][i]['mustSelectNums'][1],
          priorityCode1: row['topicList'][i]['priorityCodes'][1],
          recoveryPriorityCode1: row['topicList'][i]['recoveryPriorityCodes'][1],
          secCode1: row['topicList'][i]['secCodes'][1],
          topicName1: row['topicList'][i]['topicNames'][1],
          topicNo1: row['topicList'][i]['topicNos'][1],
          topicType1: row['topicList'][i]['topicTypes'][1]
        })
      }
      console.log(that.compareTopicForm)
    },
    compareKafka2Xml() {
      const that = this
      that.compareForm = []
      that.tmpTopicList = []
      that.compareTopicForm = []
      let orderDate = ''
      if (that.orderDate !== '') {
        orderDate = that.orderDate
      } else {
        orderDate = getToday()
      }
      const data = {
        orderDate
      }
      that.$store.dispatch('editing/compareKafka2Xml', data).then(res => {
        if (res.data) {
          console.log(res.data)
          for (let i = 0; i < res.data.length; i++) {
            that.compareForm.push({
              ID: i,
              gatherSNO: res.data[i]['gatherSno'],
              aAbbr0: res.data[i]['aabbr'][0],
              aCode0: res.data[i]['acode'][0],
              aLastDate0: res.data[i]['alastDate'][0],
              aRegDate0: res.data[i]['aregDate'][0],
              bAbbr0: res.data[i]['babbr'][0],
              bCode0: res.data[i]['bcode'][0],
              blastDate0: res.data[i]['blastDate'][0],
              internalMeetingId0: res.data[i]['internalMeetingId'][0],
              isEquall: res.data[i]['isEqual'],
              meetingBeginDate0: res.data[i]['meetingBeginDate'][0],
              meetingEndDate0: res.data[i]['meetingEndDate'][0],
              meetingName0: res.data[i]['meetingName'][0],
              meetingType0: res.data[i]['meetingType'][0],
              priorityAbbr0: res.data[i]['priorityAbbr'][0],
              priorityCode0: res.data[i]['priorityCode'][0],
              priorityLastDate0: res.data[i]['priorityLastDate'][0],
              priorityRegDate0: res.data[i]['priorityRegDate'][0],
              secAbbr0: res.data[i]['secAbbr'][0],
              secCode0: res.data[i]['secCode'][0],
              aAbbr1: res.data[i]['aabbr'][1],
              aCode1: res.data[i]['acode'][1],
              aLastDate1: res.data[i]['alastDate'][1],
              aRegDate1: res.data[i]['aregDate'][1],
              bAbbr1: res.data[i]['babbr'][1],
              bCode1: res.data[i]['bcode'][1],
              blastDate1: res.data[i]['blastDate'][1],
              internalMeetingId1: res.data[i]['internalMeetingId'][1],
              meetingBeginDate1: res.data[i]['meetingBeginDate'][1],
              meetingEndDate1: res.data[i]['meetingEndDate'][1],
              meetingName1: res.data[i]['meetingName'][1],
              meetingType1: res.data[i]['meetingType'][1],
              priorityAbbr1: res.data[i]['priorityAbbr'][1],
              priorityCode1: res.data[i]['priorityCode'][1],
              priorityLastDate1: res.data[i]['priorityLastDate'][1],
              priorityRegDate1: res.data[i]['priorityRegDate'][1],
              secAbbr1: res.data[i]['secAbbr'][1],
              secCode1: res.data[i]['secCode'][1],
              topicList: res.data[i]['compareGddhTopics']
            })
          }
        }
      }
      )
      console.log(that.compareTopicForm)
      console.log('------------------------')
      console.log(that.compareForm)
      that.compareComplete = true
    },
    getClientNamesByUser() {
      const that = this
      that.clientNames = []
      const userName = JSON.parse(that.$store.getters.userInfo).userName
      that.$store.dispatch('editing/getClientNamesByUser', userName).then(res => {
        if (res.data) {
          for (let i = 0; i < res.data.length; i++) {
            that.clientNames.push({ value: res.data[i]['ftpClientName'], label: res.data[i]['ftpClientName'] })
          }
        }
      })
    },
    saveCompareResult() {},
    forceAccess() {
      const that = this
      const gatherSNOs = []
      console.log('------------')
      console.log(that.compareForm)
      for (let i = 0; i < that.compareForm.length; i++) {
        console.log('--===========')
        console.log(that.compareForm[i])
        gatherSNOs.push(that.compareForm[i]['gatherSNO'])
      }
      const data = {
        gatherSNOs
      }
      console.log(data)
      that.$store.dispatch('editing/forceAccess', data).then(res => {
        if (res.data) {
          console.log(res.data)
        }
      })
    },
    closeCompareTable() {
      const that = this
      that.compareComplete = false
      that.compareForm = []
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
